package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Scene;
import cn.wolfcode.trip.base.mapper.SceneMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.ISceneService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SceneServiceImpl implements ISceneService {

    @Autowired
    private SceneMapper sceneMapper;

    @Override
    public PageInfo<Scene> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        return new PageInfo<>(sceneMapper.selectForList(qo));
    }

    @Override
    public void saveOrUpdate(Scene entity) {
        if (entity.getId() == null) {
            sceneMapper.insert(entity);
        } else {
            sceneMapper.updateByPrimaryKey(entity);
        }
    }

    @Override
    public List<Scene> listScenesByThemeId(Long themeId) {
        return sceneMapper.selectScenesByThemeId(themeId);
    }

    @Override
    public List<Scene> list() {
        return sceneMapper.listAll();
    }


    @Override
    public List<Scene> listScenesByRegionId(Long id) {
        return sceneMapper.selectScenesByRegionId(id);
    }

    @Override
    public List<Scene> listScenes() {
        return sceneMapper.selectAll();
    }
}
